home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_06 / saks / cat2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-08  |  467 b   |  29 lines

  1. Listing 12 - Slightly cleaner versions of the str::cat function in 
  2. Listing 11.
  3.  
  4. //
  5. // append a nul-terminated string to a str
  6. //
  7. void str::cat(const char *s)
  8.     {
  9.     len += strlen(s);
  10.     char *p = strcpy(new char[len + 1], ptr);
  11.     strcat(p, s);
  12.     delete [] ptr;
  13.     ptr = p;
  14.     }
  15.  
  16. //
  17. // append a str to a str
  18. //
  19. void str::cat(const str &s)
  20.     {
  21.     len += s.len;
  22.     char *p = strcpy(new char[len + 1], ptr);
  23.     strcat(p, s.ptr);
  24.     delete [] ptr;
  25.     ptr = p;
  26.     }
  27.  
  28.  
  29.